﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIController : MonoBehaviour
{

    [SerializeField] private Text scoreLable;
    [SerializeField] private SettingsPopup settingsPopup;

    private int _score;

    void Awake()
    {
        Messenger.AddListener(GameEvent.ENEMY_HIT,OnEnemyHit);
    }

	// Use this for initialization
	void Start ()
	{
	    _score = 0;
	    scoreLable.text = _score.ToString();
	    settingsPopup.Close();
	}
	
	// Update is called once per frame
	void Update ()
	{
	    scoreLable.text = Time.realtimeSinceStartup.ToString();
	}

    public void OnOpenSettings()
    {
        settingsPopup.Open();
//        Debug.Log("open settings");
    }

    public void OnPointerDown()
    {
        Debug.Log("pointer down");
    }

    void onDestroy()
    {
        //当对象被摧毁时，使用清除侦听器防止出错
        Messenger.RemoveListener(GameEvent.ENEMY_HIT,OnEnemyHit);
    }

    private void OnEnemyHit()
    {
        _score += 1;
        scoreLable.text = _score.ToString();
    }
}
